﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LispInterpretor;
using LispInterpretor.DataTypes;

namespace UnitTests
{
    [TestClass]
    public class TestDefine
    {
        [TestMethod]
        public void TestSimpleDefine()
        {
            var env = new LispInterpretor.Environment();

            Evaluator.Eval("(def a 3)", env);

            Assert.AreEqual(new Number(3), Evaluator.Eval("a", env));
        }

        [TestMethod]
        public void TestLambdaDefine()
        {
            var env = new LispInterpretor.Environment();

            Evaluator.Eval("(def sqr (\\ (a) (* a a)))", env);

            var result = Evaluator.Eval("(sqr 5)", env);

            Assert.AreEqual(new Number(25), result);
        }

        [TestMethod]
        public void TestRecursiveProcedure()
        {
            var env = new LispInterpretor.Environment();

            Evaluator.Eval("(def fact (\\ (n) (if (= n 0) 1 (* n (fact (- n 1)))))", env);

            var result = Evaluator.Eval("(fact 5)", env);

            Assert.AreEqual(new Number(120), result);
        }
    }
}
